/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Models;

import java.security.*;
import java.sql.*;
import java.util.Vector;

import Beans.NhanVien;
import Beans.PhanQuyenNhom;
import Beans.NhomNhanVien;


/**
 *
 * @author VIC
 */
public class NhanVien_Model {

    public static String SHA1(String pw) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA1");
            md.update(pw.getBytes());
            byte[] b = md.digest();
            char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7',
                '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
            StringBuffer buf = new StringBuffer();
            for (int j = 0; j < b.length; j++) {
                buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
                buf.append(hexDigit[b[j] & 0x0f]);
            }
            pw = buf.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return pw;
        }
        return pw;
    }

    public static NhanVien LayThongTin(String usert, String passt) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String user = usert.replace("'", "");
            user = user.replace("\"", "");
            user = user.replace("&", "");
            String pass = passt.replace("'", "");
            pass = pass.replace("\"", "");
            pass = pass.replace("&", "");
            String usSHA1 = SHA1(user);
            String pwSHA1 = SHA1(pass);
            String query = "Select * from NhanVien where TenDN = '" + usSHA1 + "' and MatKhau = '" + pwSHA1 + "' and TinhTrang = 1 ";
            rss = stmt.executeQuery(query);
            NhanVien nv = new NhanVien();
            while (rss.next()) {
                nv.setMaNV(rss.getInt(1));
                nv.setMaNNV(rss.getInt(2));
                nv.setHoTen(rss.getString(3));
                nv.setDiaChi(rss.getString(4));
                nv.setSoDT(rss.getString(5));
                nv.setNgayVaoLam(rss.getString(6));
                nv.setTinhTrang(rss.getByte(7));
                nv.setTenDN(rss.getString(8));
                nv.setMatKhau(rss.getString(9));
            }
            stmt.close();
            rss.close();
            conn.close();
            return nv;
        } catch (Exception e) {
            e.printStackTrace();

            return null;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static String LayTenNV(int manv) {

        String tennv = "";
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select HoTen from nhanvien where MaNV = " + manv;
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                tennv = rss.getString(1);
            }
            stmt.close();
            rss.close();
            conn.close();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return tennv;
    }

    public static String LayDiaChi(int manv) {

        String diachi = "";
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select DiaChi from nhanvien where MaNV = " + manv;
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                diachi = rss.getString(1);
            }
            stmt.close();
            rss.close();
            conn.close();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return diachi;
    }

    public static String LaySoDT(int manv) {

        String sodt = "";
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select SoDT from nhanvien where MaNV = " + manv;
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                sodt = rss.getString(1);
            }
            stmt.close();
            rss.close();
            conn.close();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return sodt;
    }

    public Vector LayDSNNV(int langid) {
        Vector v = new Vector();
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select * from nhomnhanvien where MaNN = " + langid + " ";
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.NhomNhanVien nnv = new Beans.NhomNhanVien();
                nnv.setMaNNV(rss.getInt(1));
                nnv.setMaNN(rss.getInt(2));
                nnv.setTenNNV(rss.getString(3));

                v.add(nnv);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public Vector LayDSNV() {

        Vector v = new Vector();
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select * from nhanvien Order by MaNV desc";
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.NhanVien nv = new Beans.NhanVien();
                nv.setMaNV(rss.getInt(1));
                nv.setMaNNV(rss.getInt(2));
                nv.setHoTen(rss.getString(3));
                nv.setDiaChi(rss.getString(4));
                nv.setSoDT(rss.getString(5));
                nv.setNgayVaoLam(rss.getString(6));
                nv.setTinhTrang(rss.getByte(7));
                nv.setTenDN(rss.getString(8));
                nv.setMatKhau(rss.getString(9));

                v.add(nv);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();

        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public static int TaoMa() {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select max(manv) from nhanvien";

            rss = stmt.executeQuery(query);
            int maht = 0;// biến maht chứa mã của khu vực hiện tại
            while (rss.next()) {
                maht = rss.getInt(1);
            }
            stmt.close();
            rss.close();
            conn.close();
            return maht + 1;
        } catch (Exception e) {
            e.printStackTrace();

            return 0;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static boolean TaoNhanVien(String tennv, String username, String nnv, String diachi, String sodt, String ngayvaolam) {
        Connection conn = null;

        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            int manv = TaoMa();
            int nnvv = Integer.parseInt(nnv);
            String user = username.replace("'", "");
            user = user.replace("\"", "");
            user = user.replace("&", "");
            String passt = "12345";
            String pass = passt.replace("'", "");
            pass = pass.replace("\"", "");
            pass = pass.replace("&", "");
            String usSHA1 = SHA1(user);
            String pwSHA1 = SHA1(pass);
            PhanQuyenNhom[] dsnn = PhanQuyenNhom_Model.DSNhomQuyen(nnvv);
            String query = "insert into nhanvien values (" + manv + ", " + nnvv + ", '" + tennv + "', '" + diachi + "', '" + sodt + "', '" + ngayvaolam + "', 1, '" + usSHA1 + "', '" + pwSHA1 + "' ) ";
            String x = "insert into phanquyencanhan values ";
            for (int i = 0; i < dsnn.length; i++) {
                if (CheckQuyenNhom(dsnn[i].getMaQuyen(), nnvv)) {
                    x = x + "(" + dsnn[i].getMaQuyen() + ", " + manv + ", 1),";
                } else {
                    x = x + "(" + dsnn[i].getMaQuyen() + ", " + manv + ", 0),";
                }

            }
            String query2 = x.substring(0, x.length() - 1);
            int n = stmt.executeUpdate(query);
            int m = stmt.executeUpdate(query2);
            stmt.close();
            conn.close();
            if (n == 0) {
                return false;// thất bại
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();

            return false;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }

            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static NhomNhanVien[] DSNhom(int mannv, int langid) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        Vector dsnn = new Vector();// biáº¿n dsnn lÆ°u danh sÃ¡ch ngÃ´n ngá»¯ hiá»‡n cÃ³.
        String query = "";
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();

            query = "Select * from nhomnhanvien where MaNNV != " + mannv + " and MaNN = " + langid;
            rss = stmt.executeQuery(query);
            //rss = ConnectionPool.Select(query);
            while (rss.next()) {
                NhomNhanVien nnv = new NhomNhanVien();
                nnv.setMaNNV(rss.getInt(1));
                nnv.setMaNN(rss.getInt(2));
                nnv.setTenNNV(rss.getString(3));

                dsnn.add(nnv);
            }
            stmt.close();
            rss.close();
            conn.close();
            return convertToArray(dsnn);
        } catch (Exception e) {
            e.printStackTrace();

            return null;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static NhomNhanVien[] DanhSachNhom(int langid) {
        Vector dsnn = new Vector();
        String query = "";
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            query = "Select * from nhomnhanvien where MaNN = " + langid;
            rss = stmt.executeQuery(query);
            //rss = ConnectionPool.Select(query);
            while (rss.next()) {
                NhomNhanVien nnv = new NhomNhanVien();
                nnv.setMaNNV(rss.getInt(1));
                nnv.setMaNN(rss.getInt(2));
                nnv.setTenNNV(rss.getString(3));

                dsnn.add(nnv);
            }
            stmt.close();
            rss.close();
            conn.close();
            return convertToArray(dsnn);
        } catch (Exception e) {
            e.printStackTrace();

            return null;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static NhomNhanVien[] convertToArray(Vector v) {
        int n = v.size();
        NhomNhanVien[] arr = new NhomNhanVien[n];
        for (int i = 0; i < n; i++) {
            arr[i] = (NhomNhanVien) v.get(i);
        }
        return arr;
    }

    public static String LayTenNhom(int mannv, int langid) {

        String maht = "";
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select TenNNV from nhomnhanvien where MaNN = " + langid + " and MaNNV = " + mannv;

            rss = stmt.executeQuery(query);

            while (rss.next()) {
                maht = rss.getString(1);
            }
            stmt.close();
            rss.close();
            conn.close();

        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return maht;
    }

    public static boolean UpdateNNV(String mannv, String manv) {
        Connection conn = null;

        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "Update nhanvien set MaNNV = " + mannv + " where MaNV = " + manv;            
            int n = stmt.executeUpdate(query);
            String query1 = " Delete from phanquyencanhan where MaNV = " + manv + " ";
            stmt.executeUpdate(query1);
            int nnvv = Integer.parseInt(mannv);
            PhanQuyenNhom[] dsnn = PhanQuyenNhom_Model.DSNhomQuyen(nnvv);
            String x = "insert into phanquyencanhan values ";
            for (int i = 0; i < dsnn.length; i++) {
                x = x + "(" + dsnn[i].getMaQuyen() + ", " + manv + ", 1),";
            }
            String query2 = x.substring(0, x.length() - 1);
            stmt.executeUpdate(query2);
            stmt.close();
            conn.close();
            if (n == 0) {
                return false;// thất bại
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();

            return false;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static boolean UpdateStatusNV(String status, String manv) {
        Connection conn = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "Update nhanvien set TinhTrang = " + status + " where MaNV = " + manv;
            int n = stmt.executeUpdate(query);
            stmt.close();

            conn.close();
            if (n == 0) {
                return false;// thất bại
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();

            return false;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }

            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static boolean Changepass(String tennv, String newpass, String diachi, String sodt, int MaNV) {
        Connection conn = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "";
            if(newpass.equals("")){
                query = "Update nhanvien set HoTen = '" + tennv + "', DiaChi = '"+diachi+"', SoDT = '"+sodt+"' where MaNV = " + MaNV;
            }
            else{
                String pass = newpass.replace("'", "");
                pass = pass.replace("\"", "");
                pass = pass.replace("&", "");
                String pwSHA1 = SHA1(pass);
                query = "Update nhanvien set HoTen = '" + tennv + "', DiaChi = '"+diachi+"', SoDT = '"+sodt+"', MatKhau = '"+pwSHA1+"' where MaNV = " + MaNV;
            }
            int n = stmt.executeUpdate(query);
            stmt.close();

            conn.close();
            if (n == 0) {
                return false;// thất bại
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();

            return false;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }

            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public Vector SortHoTenNV(String order) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        Vector v = new Vector();
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select * from nhanvien Order by HoTen " + order;
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.NhanVien nv = new Beans.NhanVien();
                nv.setMaNV(rss.getInt(1));
                nv.setMaNNV(rss.getInt(2));
                nv.setHoTen(rss.getString(3));
                nv.setDiaChi(rss.getString(4));
                nv.setSoDT(rss.getString(5));
                nv.setNgayVaoLam(rss.getString(6));
                nv.setTinhTrang(rss.getByte(7));
                nv.setTenDN(rss.getString(8));
                nv.setMatKhau(rss.getString(9));
                v.add(nv);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();

        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public Vector SortNgayVaoLam(String order) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        Vector v = new Vector();
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select * from nhanvien Order by NgayVaoLam " + order;
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.NhanVien nv = new Beans.NhanVien();
                nv.setMaNV(rss.getInt(1));
                nv.setMaNNV(rss.getInt(2));
                nv.setHoTen(rss.getString(3));
                nv.setDiaChi(rss.getString(4));
                nv.setSoDT(rss.getString(5));
                nv.setNgayVaoLam(rss.getString(6));
                nv.setTinhTrang(rss.getByte(7));
                nv.setTenDN(rss.getString(8));
                nv.setMatKhau(rss.getString(9));
                v.add(nv);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();

        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public Vector SortNhomNV(int langid, String order) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        Vector v = new Vector();
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select MaNV, A.MaNNV, HoTen, DiaChi, SoDT, NgayVaoLam, TinhTrang, TenDN, MatKhau, TenNNV   from nhanvien A, nhomnhanvien B where A.MaNNV = B.MaNNV and B.MaNN = " + langid + " Order by TenNNV " + order;
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.NhanVien nv = new Beans.NhanVien();
                nv.setMaNV(rss.getInt(1));
                nv.setMaNNV(rss.getInt(2));
                nv.setHoTen(rss.getString(3));
                nv.setDiaChi(rss.getString(4));
                nv.setSoDT(rss.getString(5));
                nv.setNgayVaoLam(rss.getString(6));
                nv.setTinhTrang(rss.getByte(7));
                nv.setTenDN(rss.getString(8));
                nv.setMatKhau(rss.getString(9));
                v.add(nv);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();

        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public Vector SortTTNV(String order) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        Vector v = new Vector();
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select * from nhanvien Order by TinhTrang " + order;
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.NhanVien nv = new Beans.NhanVien();
                nv.setMaNV(rss.getInt(1));
                nv.setMaNNV(rss.getInt(2));
                nv.setHoTen(rss.getString(3));
                nv.setDiaChi(rss.getString(4));
                nv.setSoDT(rss.getString(5));
                nv.setNgayVaoLam(rss.getString(6));
                nv.setTinhTrang(rss.getByte(7));
                nv.setTenDN(rss.getString(8));
                nv.setMatKhau(rss.getString(9));
                v.add(nv);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();

        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public Vector SearchUser(String HOTEN, String NGAYVAOLAM, String NHOMNHANVIEN, String TINHTRANG, int langid) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        Vector v = new Vector();
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();

            String query = " select MaNV, A.MaNNV, HoTen, DiaChi, SoDT, NgayVaoLam, TinhTrang, TenDN, MatKhau " +
                           " from nhanvien A, nhomnhanvien B" +
                           " where A.MaNNV = B.MaNNV and B.MaNN = "+langid+" ";
            String[] arr = {HOTEN, NGAYVAOLAM, NHOMNHANVIEN, TINHTRANG};
            for (int i = 0; i < arr.length; i++) {
                if (!arr[i].equals("")  && arr[i].equals(HOTEN)) {
                    query = query + " and HoTen like '%" + arr[i] + "%' ";
                }
                if (!arr[i].equals("")  && arr[i].equals(NGAYVAOLAM)) {
                    query = query + " and NgayVaoLam like '%" + arr[i] + "%' ";
                }
                if (!arr[i].equals("") && !arr[i].equals("all") && arr[i].equals(NHOMNHANVIEN)) {
                    query = query + " and A.MaNNV = " + arr[i] + " ";
                }
                if (!arr[i].equals("") && !arr[i].equals("all") && arr[i].equals(TINHTRANG)) {
                    query = query + " and TinhTrang = " + arr[i] + " ";
                }
            }

            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.NhanVien nv = new Beans.NhanVien();
                nv.setMaNV(rss.getInt(1));
                nv.setMaNNV(rss.getInt(2));
                nv.setHoTen(rss.getString(3));
                nv.setDiaChi(rss.getString(4));
                nv.setSoDT(rss.getString(5));
                nv.setNgayVaoLam(rss.getString(6));
                nv.setTinhTrang(rss.getByte(7));
                nv.setTenDN(rss.getString(8));
                nv.setMatKhau(rss.getString(9));
                v.add(nv);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();

        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public Vector SortSearchHoTenNV(int langid, String order, String HOTEN, String NGAYVAOLAM, String NHOMNHANVIEN, String TINHTRANG) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        Vector v = new Vector();
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();

            String query = " select MaNV, A.MaNNV, HoTen, DiaChi, SoDT, NgayVaoLam, TinhTrang, TenDN, MatKhau " +
                           " from nhanvien A, nhomnhanvien B" +
                           " where A.MaNNV = B.MaNNV and B.MaNN = "+langid+" ";
            String[] arr = {HOTEN, NGAYVAOLAM, NHOMNHANVIEN, TINHTRANG};
            for (int i = 0; i < arr.length; i++) {
                if (!arr[i].equals("")  && arr[i].equals(HOTEN)) {
                    query = query + " and HoTen like '%" + arr[i] + "%' ";
                }
                if (!arr[i].equals("")  && arr[i].equals(NGAYVAOLAM)) {
                    query = query + " and NgayVaoLam like '%" + arr[i] + "%' ";
                }
                if (!arr[i].equals("") && !arr[i].equals("all") && arr[i].equals(NHOMNHANVIEN)) {
                    query = query + " and A.MaNNV = " + arr[i] + " ";
                }
                if (!arr[i].equals("") && !arr[i].equals("all") && arr[i].equals(TINHTRANG)) {
                    query = query + " and TinhTrang = " + arr[i] + " ";
                }
            }
            query = query + "Order by HoTen "+order;
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.NhanVien nv = new Beans.NhanVien();
                nv.setMaNV(rss.getInt(1));
                nv.setMaNNV(rss.getInt(2));
                nv.setHoTen(rss.getString(3));
                nv.setDiaChi(rss.getString(4));
                nv.setSoDT(rss.getString(5));
                nv.setNgayVaoLam(rss.getString(6));
                nv.setTinhTrang(rss.getByte(7));
                nv.setTenDN(rss.getString(8));
                nv.setMatKhau(rss.getString(9));
                v.add(nv);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();

        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public Vector SortSearchNgayVaoLam(int langid, String order, String HOTEN, String NGAYVAOLAM, String NHOMNHANVIEN, String TINHTRANG) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        Vector v = new Vector();
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();

            String query = " select MaNV, A.MaNNV, HoTen, DiaChi, SoDT, NgayVaoLam, TinhTrang, TenDN, MatKhau " +
                           " from nhanvien A, nhomnhanvien B " +
                           " where A.MaNNV = B.MaNNV and B.MaNN = "+langid+" ";
            String[] arr = {HOTEN, NGAYVAOLAM, NHOMNHANVIEN, TINHTRANG};
            for (int i = 0; i < arr.length; i++) {
                if (!arr[i].equals("")  && arr[i].equals(HOTEN)) {
                    query = query + " and HoTen like '%" + arr[i] + "%' ";
                }
                if (!arr[i].equals("")  && arr[i].equals(NGAYVAOLAM)) {
                    query = query + " and NgayVaoLam like '%" + arr[i] + "%' ";
                }
                if (!arr[i].equals("") && !arr[i].equals("all") && arr[i].equals(NHOMNHANVIEN)) {
                    query = query + " and A.MaNNV = " + arr[i] + " ";
                }
                if (!arr[i].equals("") && !arr[i].equals("all") && arr[i].equals(TINHTRANG)) {
                    query = query + " and TinhTrang = " + arr[i] + " ";
                }
            }
            query = query + "Order by NgayVaoLam "+order;
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.NhanVien nv = new Beans.NhanVien();
                nv.setMaNV(rss.getInt(1));
                nv.setMaNNV(rss.getInt(2));
                nv.setHoTen(rss.getString(3));
                nv.setDiaChi(rss.getString(4));
                nv.setSoDT(rss.getString(5));
                nv.setNgayVaoLam(rss.getString(6));
                nv.setTinhTrang(rss.getByte(7));
                nv.setTenDN(rss.getString(8));
                nv.setMatKhau(rss.getString(9));
                v.add(nv);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();

        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public Vector SortSearchNhomNV(int langid, String order, String HOTEN, String NGAYVAOLAM, String NHOMNHANVIEN, String TINHTRANG) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        Vector v = new Vector();
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();

            String query = " select MaNV, A.MaNNV, HoTen, DiaChi, SoDT, NgayVaoLam, TinhTrang, TenDN, MatKhau " +
                           " from nhanvien A, nhomnhanvien B " +
                           " where A.MaNNV = B.MaNNV and B.MaNN = "+langid+" ";
            String[] arr = {HOTEN, NGAYVAOLAM, NHOMNHANVIEN, TINHTRANG};
            for (int i = 0; i < arr.length; i++) {
                if (!arr[i].equals("")  && arr[i].equals(HOTEN)) {
                    query = query + " and HoTen like '%" + arr[i] + "%' ";
                }
                if (!arr[i].equals("")  && arr[i].equals(NGAYVAOLAM)) {
                    query = query + " and NgayVaoLam like '%" + arr[i] + "%' ";
                }
                if (!arr[i].equals("") && !arr[i].equals("all") && arr[i].equals(NHOMNHANVIEN)) {
                    query = query + " and A.MaNNV = " + arr[i] + " ";
                }
                if (!arr[i].equals("") && !arr[i].equals("all") && arr[i].equals(TINHTRANG)) {
                    query = query + " and TinhTrang = " + arr[i] + " ";
                }
            }
            query = query + "Order by TenNNV "+order;

            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.NhanVien nv = new Beans.NhanVien();
                nv.setMaNV(rss.getInt(1));
                nv.setMaNNV(rss.getInt(2));
                nv.setHoTen(rss.getString(3));
                nv.setDiaChi(rss.getString(4));
                nv.setSoDT(rss.getString(5));
                nv.setNgayVaoLam(rss.getString(6));
                nv.setTinhTrang(rss.getByte(7));
                nv.setTenDN(rss.getString(8));
                nv.setMatKhau(rss.getString(9));
                v.add(nv);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();

        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public Vector SortSearchTTNV(int langid, String order, String HOTEN, String NGAYVAOLAM, String NHOMNHANVIEN, String TINHTRANG) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        Vector v = new Vector();
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();

            String query = " select MaNV, A.MaNNV, HoTen, DiaChi, SoDT, NgayVaoLam, TinhTrang, TenDN, MatKhau " +
                           " from nhanvien A, nhomnhanvien B " +
                           " where A.MaNNV = B.MaNNV and B.MaNN = "+langid+" ";
            String[] arr = {HOTEN, NGAYVAOLAM, NHOMNHANVIEN, TINHTRANG};
            for (int i = 0; i < arr.length; i++) {
                if (!arr[i].equals("")  && arr[i].equals(HOTEN)) {
                    query = query + " and HoTen like '%" + arr[i] + "%' ";
                }
                if (!arr[i].equals("")  && arr[i].equals(NGAYVAOLAM)) {
                    query = query + " and NgayVaoLam like '%" + arr[i] + "%' ";
                }
                if (!arr[i].equals("") && !arr[i].equals("all") && arr[i].equals(NHOMNHANVIEN)) {
                    query = query + " and A.MaNNV = " + arr[i] + " ";
                }
                if (!arr[i].equals("") && !arr[i].equals("all") && arr[i].equals(TINHTRANG)) {
                    query = query + " and TinhTrang = " + arr[i] + " ";
                }
            }
            query = query + "Order by TinhTrang "+order;

            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.NhanVien nv = new Beans.NhanVien();
                nv.setMaNV(rss.getInt(1));
                nv.setMaNNV(rss.getInt(2));
                nv.setHoTen(rss.getString(3));
                nv.setDiaChi(rss.getString(4));
                nv.setSoDT(rss.getString(5));
                nv.setNgayVaoLam(rss.getString(6));
                nv.setTinhTrang(rss.getByte(7));
                nv.setTenDN(rss.getString(8));
                nv.setMatKhau(rss.getString(9));
                v.add(nv);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();

        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public Vector Detail(String manv) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        Vector v = new Vector();
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select * from nhanvien where MaNV = " + manv + " ";

            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.NhanVien nv = new Beans.NhanVien();
                nv.setMaNV(rss.getInt(1));
                nv.setMaNNV(rss.getInt(2));
                nv.setHoTen(rss.getString(3));
                nv.setDiaChi(rss.getString(4));
                nv.setSoDT(rss.getString(5));
                nv.setNgayVaoLam(rss.getString(6));
                nv.setTinhTrang(rss.getByte(7));
                nv.setTenDN(rss.getString(8));
                nv.setMatKhau(rss.getString(9));
                v.add(nv);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public Vector ShowQuyen() {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        Vector v = new Vector();
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = " select * from phanquyennhom where TinhTrang = 1 ";
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.NhanVien nv = new Beans.NhanVien();
                nv.setMaNV(rss.getInt(1));
                nv.setMaNNV(rss.getInt(2));
                nv.setHoTen(rss.getString(3));
                nv.setDiaChi(rss.getString(4));
                nv.setSoDT(rss.getString(5));
                nv.setNgayVaoLam(rss.getString(6));
                nv.setTinhTrang(rss.getByte(7));
                nv.setTenDN(rss.getString(8));
                nv.setMatKhau(rss.getString(9));

                v.add(nv);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();

        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public static String LayTenQuyen(int maquyen, int langid) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        String maht = "";
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select TenQuyen from quyen where MaNN = " + langid + " and MaQuyen = " + maquyen + " ";
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                maht = rss.getString(1);
            }
            stmt.close();
            rss.close();
            conn.close();

        } catch (Exception e) {
            e.printStackTrace();


        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return maht;
    }

    public static boolean CheckQuyen(int maquyen, int manv) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            int n = 0;
            String query = "select * from phanquyencanhan where MaQuyen = " + maquyen + " and MaNV = " + manv + " and TinhTrang = 1";
            rss = stmt.executeQuery(query);            
            while (rss.next()) {                
                n = n + 1;
            }
            stmt.close();
            rss.close();
            conn.close();
            if (n == 0) {
                return false;// thất bại
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static boolean CheckQuyenNhom(int maquyen, int mannv) {
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            int n = 0;
            String query = "select * from phanquyennhom where MaQuyen = " + maquyen + " and MaNNV = " + mannv + " and TinhTrang = 1";
            rss = stmt.executeQuery(query);            
            while (rss.next()) {                
                n = n + 1;
            }
            stmt.close();
            rss.close();
            conn.close();
            if (n == 0) {
                return false;// thất bại
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static boolean AddQuyenCaNhan(String maquyen, String manv) {
        Connection conn = null;

        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "Update phanquyencanhan set TinhTrang = 1  where MaQuyen = " + maquyen + " and MaNV = " + manv + "";
            int n = stmt.executeUpdate(query);
            if(n == 0){
                String query1 = " Insert into phanquyencanhan values ("+maquyen+", "+manv+", 1) ";
                stmt.executeUpdate(query1);
            }
            stmt.close();
            conn.close();            
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }

            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static boolean AddQuyenNhom(String maquyen, String mannv) {
        Connection conn = null;

        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "Update phanquyennhom set TinhTrang = 1  where MaQuyen = " + maquyen + " and MaNNV = " + mannv + "";
            String query1 = "Update phanquyencanhan set TinhTrang = 1  where MaQuyen = " + maquyen + " ";
            stmt.executeUpdate(query);
            stmt.executeUpdate(query1);
            stmt.close();
            conn.close();            
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }

            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static boolean RemoveQuyenCaNhan(String maquyen, String manv) {
        Connection conn = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "Update phanquyencanhan set TinhTrang = 0  where MaQuyen = " + maquyen + "  and MaNV = " + manv + " ";
            stmt.executeUpdate(query);
            stmt.close();
            conn.close();            
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static boolean RemoveQuyenNhom(String maquyen, String mannv) {
        Connection conn = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "Update phanquyennhom set TinhTrang = 0  where MaQuyen = " + maquyen + "  and MaNNV = " + mannv + " ";
            stmt.executeUpdate(query);
            String query1 = "Update phanquyencanhan set TinhTrang = 0  where MaQuyen = " + maquyen + " ";
            stmt.executeUpdate(query1);
            stmt.close();
            conn.close();            
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }

            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static boolean UpdateDetailNV(String manv, String tennv, String diachi, String sodt, String ngayvaolam) {
        Connection conn = null;

        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "Update nhanvien set HoTen = '" + tennv + "', DiaChi = '" + diachi + "', SoDT = '" + sodt + "', NgayVaoLam = '" + ngayvaolam + "' where  MaNV = " + manv + " ";
            int n = stmt.executeUpdate(query);
            stmt.close();
            conn.close();
            if (n == 0) {
                return false;// thất bại
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }

            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
    }

    public static Vector LayDSQuyenNV(int manv) {
        Vector v = new Vector();
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select * from phanquyencanhan where MaNV = " + manv + " and TinhTrang = 1 ";
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                Beans.PhanQuyenCaNhan cn = new Beans.PhanQuyenCaNhan();
                cn.setMaQuyen(rss.getInt(1));
                cn.setMaNV(rss.getInt(2));
                cn.setTinhTrang(rss.getByte(3));
                v.add(cn);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.getMessage();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return v;
    }

    public static int LayMaNNV(int manv) {
        int MaNNV = 0;
        Connection conn = null;
        ResultSet rss = null;
        Statement stmt = null;
        try {
            ConnectionPool pool = new ConnectionPool();
            conn = pool.getConnection();
            stmt = conn.createStatement();
            String query = "select MaNNV from nhanvien where MaNV = " + manv + " ";
            rss = stmt.executeQuery(query);
            while (rss.next()) {
                MaNNV = rss.getInt(1);
            }
            stmt.close();
            rss.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                }
            }
            if (rss != null) {
                try {
                    rss.close();
                } catch (SQLException e) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                }
            }
        }
        return MaNNV;
    }
}
